package com.zoran.study.spring.validation.constraint;

import com.zoran.study.spring.validation.validator.SecureTextValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * Secure text constraint. Forbid [\"';<>/!].
 *
 * @author Winter Gao
 *
 */
@Documented
@Retention(RUNTIME)
@Target({ FIELD, PARAMETER })
@Constraint(validatedBy = { SecureTextValidator.class })
public @interface SecureText {

    String message() default "{geerong.validation.constraints.SecureText.message}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * forbidden characters pattern.
     */
    String pattern() default "^[^\"';></!]+$";

}
